import Joi from "joi";

const Login = Joi.object<DTO.User.LoginParams>({
  username: Joi.string().required(),
  password: Joi.string().required()
});

const UpdatePassword = Joi.object<DTO.User.UpdatePasswordParams>({
  originPassword: Joi.string().required(),
  newPassword: Joi.string().required()
});

const CreateUser = Joi.object<DTO.User.CreateUserParams>({
  username: Joi.string().required(),
  nickname: Joi.string().required(),
  phone: Joi.string().allow(""),
  department: Joi.string().allow("")
});

const DeleteUser = Joi.object<DTO.User.DeleteUserParams>({
  id: Joi.number().required()
});

const DeleteUsers = Joi.object<DTO.User.DeleteUsersParams>({
  ids: Joi.array().items(Joi.number()).required()
});

const UpdateUser = Joi.object<DTO.User.UpdateUserParams>({
  id: Joi.number().required(),
  username: Joi.string().allow(""),
  nickname: Joi.string().allow(""),
  phone: Joi.string().allow("", null),
  role: Joi.number(),
  department: Joi.string().allow("")
});

const ListUser = Joi.object<DTO.User.ListUserParams>({
  keyword: Joi.string().allow(""),
  pageNum: Joi.number(),
  pageSize: Joi.number()
});

export const UserSchema = {
  Login,
  UpdatePassword,
  CreateUser,
  DeleteUser,
  DeleteUsers,
  UpdateUser,
  ListUser
};
